

var p = new Promise((resolve, reject) => {
    console.log("new Promise()");
    resolve("resolve promise");
});

console.log("main path");

setTimeout(() => {
    console.log("setTimeout");
}, 0);
var m = new MessageChannel();
m.port1.onmessage = function ({data}) {
    console.log("MessageChannel onmessage", data);
    //总是先于setTimeout，后于promise的then执行
}
m.port2.postMessage(null);


requestAnimationFrame(function () {
    console.log("requestAnimationFrame running")
})

m.port2.postMessage("2 times");
p.then(r => {
    console.log(r);
})